***************** Summary Stats (Table 1) **********************************	

use "$data/tech_cell_input.dta", clear	

macro def  b_controls_off "lang_control  share_off_speakers" 


keep if cells_50km_stateborders == 1
drop if year == 1996
	
egen t = group(year)
xtset id t

gen post = (year > 2007)
sum post if year < 2008

gen lang_control_post = lang_control * post

label var lang_control_post "Lang Control * Post"

qui reghdfe hyv_share lang_control_post c.share_off_speakers#i.t if cells_50km_stateborders == 1 & dhyv_share2011 !=. & dhyv_share2016 !=. [aw=pop2001], a(i.id i.subdist_border_id##i.t c.sharecrop_all_fao#i.t c.median_DIST_TOWN#i.t i.district_MCA_s##i.t) cluster(tahsil_id)

gen in_sample = e(sample)

label var MAINWORK_P "Working Population"
label var share_farmers "Share of farmers"
label var agriland_share "Share of agricultural land"
label var lang_control "Share of non-state language speakers"
label var share_off_speakers "Share of official language speakers"
label var hyv_share2006 "HYV Share (2007)"

estpost tabstat MAINWORK_P share_farmers agriland_share $b_controls_off hyv_share2006 if year == 2011 & in_sample & cells_50km_stateborders == 1 & dhyv_share2011 !=. & dhyv_share2016 !=. & lang_control !=. [aw=pop2001] , stat(mean sd N) columns(statistics)

esttab using "$results/tables/table_1a.tex", replace ///
cells("mean(fmt(%9.3fc)) sd(fmt(%9.3fc)) count(fmt(%9.0fc))") ///
nonumber nomtitle nonote noobs label ///
refcat(MAINWORK_P "Baseline cell characteristics", nolabel) ///
collabels("Mean" "Standard Deviation" "N")

label var hyv_share "HYV Share"
label var fert_share_total "Fertilizer Share"
label var irr_share_total "Irrigation Share"

estpost tabstat hyv_share fert_share_total irr_share_total if in_sample == 1  & cells_50km_stateborders == 1 & dhyv_share2011 !=. & dhyv_share2016 !=. & lang_control !=. [aw=pop2001] , stat(mean sd N) columns(statistics)

esttab using "$results/tables/table_1c.tex", replace ///
cells("mean(fmt(%9.3fc)) sd(fmt(%9.3fc)) count(fmt(%9.0fc))") ///
nonumber nomtitle nonote noobs label /// 
collabels("Mean" "Standard Deviation" "N")

****** Summary stats for calls 
************************* Table 3 Panel A- Calls *************************

use "$data/calls_cell_input.dta", clear		
drop if year > 2017
drop if year < 2006 
egen t = group(year)
		
gen post = (year > 2007)
		
gen lang_control_post = lang_control * post
label var lang_control_post "Lang Control * Post"
		
local replace replace 
	
label var lang_control_post "Lang Control * Post"
label var calls_all_per100C "All calls (per 100 farmers)"
label var calls_tech_per100C "Tech calls (per 100 farmers)"
label var calls_others_per100C "Other calls (per 100 farmers)"
	
qui reghdfe calls_all_per100C lang_control_post c.share_off_speakers#i.t if cells_50km_stateborders == 1, a(i.id i.subdist_border_id##i.t c.sharecrop_all_fao#i.t c.median_DIST_TOWN#i.t i.district_MCA_s##i.t) cluster(tahsil_id)
	
gen in_sample = e(sample)
	
estpost tabstat calls_all_per100C  calls_tech_per100C calls_others_per100C if in_sample == 1  & cells_50km_stateborders == 1 & lang_control !=.  , stat(mean sd N) columns(statistics)

esttab using "$results/tables/table_1b.tex", replace ///
cells("mean(fmt(%9.3fc)) sd(fmt(%9.3fc)) count(fmt(%9.0fc))") ///
nonumber nomtitle nonote noobs label /// 
collabels("Mean" "Standard Deviation" "N")

**************** Yield 
use "$data/yield_cell_input.dta", clear	

gen post = (year > 2007)
egen t = group(year)
gen lang_control_post = lang_control * post
label var lang_control_post "Lang Control * Post"

qui reghdfe total_yield_idt lang_control_post c.share_off_speakers#i.t if cells_50km_stateborders == 1 & cells_in_all == 1 [aw=pop2001], a(i.id i.subdist_border_id##i.t c.sharecrop_all_fao#i.t c.median_DIST_TOWN#i.t i.district_MCA_s##i.t) cluster(tahsil_id) 

gen in_sample = e(sample)

label var total_yield_idt "Yield"

estpost tabstat total_yield_idt if in_sample == 1  & cells_50km_stateborders == 1 & lang_control !=.  , stat(mean sd N) columns(statistics)

esttab using "$results/tables/table_1d.tex", replace ///
cells("mean(fmt(%9.3fc)) sd(fmt(%9.3fc)) count(fmt(%9.0fc))") ///
nonumber nomtitle nonote noobs label /// 
collabels("Mean" "Standard Deviation" "N")
